<?php


namespace Verification;


use think\Controller;
use think\Request;
use think\Session;

class Verification extends Controller
{
    public function _initialize()
    {
        $llll=empty( $this->yz());
        if($this->x !=='admin/Index/logindo'){
            if($llll){
                return     $this->error('权限不足');
            }

        }

    }


    /***
     * 验证 权限
     *
     * @param null $pp   字符串 可以从session获得
     * @return bool|void   返回结果  true or false
     */
    public function yz($pp=null){
    //拼接字符串
        $request = Request::instance();
        $m_name=$request->module();
        $c_name=$request->controller();
        $f_name= $request->action();
        $x=$m_name.'/'.$c_name.'/'.$f_name;
        $this->x=$x;
        if($x!=='admin/Index/logindo'){

            if ($x!=='admin/Index/index'){


                // 没有传参  获取session
                $string=Session::has('LOL','think');
                if (empty($string)){
                    return $this->error('登入失效!请重新登入','admin/Index/index');
                }
                $string=Session::get('LOL','think');

                array_push($string['yz'],'admin/Index/index');
                array_push($string['yz'],'admin/Index/logout');

                return in_array($x,$string['yz']);

            }else{

                return true;
            }




        }else{
            // 判断有没有传参数
            //        var_dump($pp);
            if (!empty($pp)){
                array_push($pp,'admin/Index/index');
                array_push($pp,'admin/Index/logout');
                return in_array($x,$pp);
            }


        }


    }

}